package com.sfh.alliance.beauty;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.alliance.R;
import com.sfh.alliance.widget.BaseTopView;
import com.sfh.base.mvp.IPresenter;
import com.sfh.base.ui.UIMVPActivity;
import com.sfh.base.ui.refresh.SwipeRefreshMoreLayout;
import com.sfh.entity.Beauty;
import com.sfh.pst.IPstBeauty;
import com.sfh.pst.ProxyHandler;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 功能描述:美人界面
 *
 * @author SunFeihu 孙飞虎
 * @date 2017/9/2
 */
public class BeautyListActivity extends UIMVPActivity implements
        BaseQuickAdapter.OnItemClickListener,
        SwipeRefreshMoreLayout.OnLoadingListener, IPstBeauty.IPstUserBeautyList.IVUserBeautyList {


    public static void startContentUI(Context context) {

        Intent intent = new Intent (context, BeautyListActivity.class);
        context.startActivity (intent);

    }

    BeautyAdapter adapter;

    @BindView(R.id.topView)
    BaseTopView topView;

    @BindView(R.id.ly)
    SwipeRefreshMoreLayout ly;

    IPstBeauty.IPstUserBeautyList pstUserBeautyList;

    @Override
    public IPresenter createPresenter() {

        if (pstUserBeautyList == null) {
            pstUserBeautyList = ProxyHandler.proxy (IPstBeauty.IPstUserBeautyList.class);
        }
        return pstUserBeautyList;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);
        setContentView (R.layout.beauty_activity);
        ButterKnife.bind (this);
        init ();
    }

    private void init() {

        topView.setTitle (R.drawable.title4);
        adapter = new BeautyAdapter ();
        ly.setAdapter (adapter, false);
        ly.setOnItemClickListener (this);
        ly.setOnLoadingListener (this);
        ly.onAutoRefresh ();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

        BeautyInfoActivity.startContentUI (this, this.adapter.getItem (position));
    }

    @Override
    public void onRefreshUI() {

        pstUserBeautyList.queryUserBeauty ();
    }

    @Override
    public void onLoadMoreUI() {

    }

    @Override
    public void setList(List<Beauty> data) {

        ly.onRefreshCompale (data, true);
        ly.onLoadAllCompale ();
    }

    @Override
    public void setListError(String msg) {

        ly.onLoadMoreFail ();
    }
}
